package spring.superrun.record.mvc.entity;

import spring.superrun.record.mvc.dto.ManagerAddDto;
import spring.superrun.record.mvc.dto.ManagerCookieDto;
import spring.superrun.record.mvc.dto.ManagerUpdateDto;
import spring.superrun.tool.newid.Encrypt;
import spring.superrun.tool.newid.NewIdByUUId;

import java.io.Serializable;
import java.util.Date;

/**
 * (SuperrunManager)实体类
 *
 * @author makejava
 * @since 2021-06-15 21:16:39
 */
public class SuperrunManager implements Serializable {
    private static final long serialVersionUID = -23400993013906342L;

    private String id;

    private String username;

    private String passwordhash;

    private Date createtime;

    private Integer enabled;


    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPasswordhash() {
        return passwordhash;
    }

    public void setPasswordhash(String passwordhash) {
        this.passwordhash = passwordhash;
    }

    public Date getCreatetime() {
        return createtime;
    }

    public void setCreatetime(Date createtime) {
        this.createtime = createtime;
    }

    public Integer getEnabled() {
        return enabled;
    }

    public void setEnabled(Integer enabled) {
        this.enabled = enabled;
    }

    /**
     * 添加的映射方法
     * @param dto
     * @return
     */
    public SuperrunManager Add(ManagerAddDto dto) {
        setCreatetime(new Date());
        setEnabled(dto.getEnabled());
        setPasswordhash(Encrypt.md5(dto.getPasswordhash()));
        setId("MG"+NewIdByUUId.GetUUIDNoMinus());
        setUsername(dto.getUsername());
        return this;
    }

    /**
     * 添加一个管理员
     * @param userName
     * @param password
     * @return
     */
    public SuperrunManager Add(String userName,String password){
        setCreatetime(new Date());
        setEnabled(1);
        setPasswordhash(Encrypt.md5(password));
        setId("MG"+NewIdByUUId.GetUUIDNoMinus());
        setUsername(userName);
        return this;
    }
    /**
     * 获取CookieSeesionDto
     * @return
     */
    public ManagerCookieDto GetCookieDto(){
        ManagerCookieDto dto  = new ManagerCookieDto();
        dto.setId(getId());
        dto.setCreatetime(getCreatetime());
        dto.setUsername(getUsername());
        return dto;
    }
    /**
     * 更新的映射添加方法
     * @param dto
     * @return
     */
    public SuperrunManager Update(ManagerUpdateDto dto) {
        setUsername(dto.getUsername());
        setId(dto.getId());
        setEnabled(dto.getEnabled());
        return this;
    }
}
